package blog.dao;

import jakarta.transaction.Transactional;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import blog.entity.Articletype;

public interface ArticletypeRespository extends JpaRepository<Articletype,Long> {
    
    List<Articletype> findByTypeLike(String type);
    
    Articletype findByTypeIgnoreCase(String type);
    
    List<Articletype> findByTypeLikeOrderByIdDesc(String type);
 
    List<Articletype> findByTypeLikeOrderByCreateTimeDesc(String type);
    
    @Query("select a from Articletype a where a.type = :type ")
    List<Articletype> findByType(@Param("type") String type);
    
    @Modifying
    @Query("update Articletype a set a.type = :type where a.id = :id ")
    void updateById(@Param("type") String type, @Param("id") long id);
    
    @Query(value = "SELECT * FROM t_articletype a WHERE a.type LIKE '%:name%'", nativeQuery = true)
    public Page<Articletype> getArticletypePageByName(@Param("name") String type, Pageable pageable);
}
